In [30]:
# Cross-notebook include shim
with open("nbinclude.ipynb") as nbinclude_f: # don't rename nbinclude_f
import IPython.nbformat.current
get_ipython().run_cell(IPython.nbformat.current.read(nbinclude_f, 'json').worksheets[0].cells[0].input)
In [1]:
class Motor(object):
def __init__(self):
self._throttle = 0
@property
def throttle(self):
return self._throttle
@throttle.setter
def throttle(self, value):
self._throttle = value
In [2]:
m = Motor()
In [3]:
m.throttle
Out[3]:
In [4]:
m.throttle = 30
In [5]:
m.throttle
Out[5]:
In [20]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
class LineScanCamera(object):
def __init__(self):
self._image = np.zeros(128)
@property
def image(self):
return self._image
In [15]:
cam = LineScanCamera()
In [16]:
plt.plot(cam.image)
Out[16]:
In [21]:
class Servo(object):
def __init__(self):
self._position = 0
self._velocity = 0
@property
def position(self):
return self._position
@position.setter
def position(self, value):
self._position = value
@property
def velocity(self):
return self._velocity
@velocity.setter
def velocity(self, value):
self._velocity = value
In [22]:
s = Servo()
In [23]:
s.position
Out[23]:
In [24]:
s.position = 180
In [25]:
s.position
Out[25]:
In [27]:
s.velocity
Out[27]:
In [28]:
s.velocity = 3
In [29]:
s.velocity
Out[29]:
In [46]:
class LightSensor(object):
def __init__(self):
self._light_value = 0
@property
def light_value(self):
return self._light_value
In [44]:
l = LightSensor()
In [45]:
l.light_value
Out[45]:
In [ ]:
class Flashlight(object):
def __init__(self):
self._brightness = 0
@property
def brightness(self):
return self._brightness
@brightness.setter
def brightness(self, value):
self._brightness = value